#include <REGX52.H>
#include "AT24C02.h"
#include "LCD1602.h"
#include "Delay.h"
#include "Key.h"


unsigned char keyNum=0; 

unsigned int dat=0;
void main()
{
	LCD_Init();
	LCD_ShowString(1,1,"hello!");
	while(1)
	{
		keyNum=Key_Check();
		LCD_ShowNum(2,1,dat,5);
		if(keyNum==1)
		{
			dat++;
			LCD_ShowNum(2,1,dat,5);
		}
		else if(keyNum==2)
		{
			dat--;
			LCD_ShowNum(2,1,dat,5);
		}
		else if(keyNum==3)
		{
			C02_WriteByte(dat/256,0);
			Delay(5);
			C02_WriteByte(dat%256,1);
			Delay(5);
			LCD_ShowString(1,8,"Write Ok");
			Delay(1000);
		}
		else if(keyNum==4)
		{
			dat=C02_ReadByte(1);
			dat|=C02_ReadByte(0)<<8;
		}
	}
}